package com.develop;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan("com.develop")
public class DevelopApplication {
	private static final Logger logger = LoggerFactory.getLogger(DevelopApplication.class);

	public static void main(String[] args) {
		if (args.length == 0 || args.length != 3) {
			throw new IllegalArgumentException("启动参数错误！格式为：(省份简称,厂家简称,OMC类型)");
		}
		// topic格式：JS_HUAWEI_realTimeAlarm
		System.setProperty("topicName", args[0] + "_" + args[1] + "_" + args[2] + "_" + "realTimeAlarm");
		System.setProperty("province", args[0]);
		System.setProperty("firmName", args[1]);
		System.setProperty("omcType", args[2]);
		SpringApplication.run(DevelopApplication.class, args);

		Runtime.getRuntime().addShutdownHook(new Thread() {
			@Override
			public void run() {
				try {
					// 突然停止Consumer会导致消息重复读的情况，为了避免这种情况在shutdown之前通过让Consumer有时间将offset同步到zookeeper
					Thread.sleep(10000);
					logger.info("业务处理应用已关闭");
				} catch (InterruptedException e) {
					e.printStackTrace();
					logger.info("业务处理应用关闭异常,可能存在重复读topic的情况");
				}
			}
		});
		logger.info("5gAlarmBusiness已启动...");
	}
}
